﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.baseBLL;
using dhDataAcess.linqDAL;

namespace dhSystemBLL.basicData
{
   public  class queryMasterBLL
    {
       private queryMasterTableAdapter _queryMasterAdapter = null;
       private queryMasterTableAdapter queryMasterAdapter
        {
            get
            {
                if (_queryMasterAdapter == null) _queryMasterAdapter = new queryMasterTableAdapter();
                return _queryMasterAdapter;
            }
        }
        /// <summary>
        /// 查询查询主表表格
        /// </summary>
        /// <returns></returns>

       public sysDataSet.queryMasterDataTable getqueryMasterAll()
        {
            try
            {
                return queryMasterAdapter.GetDataqueryMasterALL();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

       /// <summary>
       /// 根据用户编号、模块编号、查询编号来查询查询主表表格
       /// </summary>
       /// <returns></returns>
       public sysDataSet.queryMasterDataTable getqueryMasterAll(string userNum,string queryNum,string moduleNum)
       {
           try
           {
               return queryMasterAdapter.GetDataByQueryMasterByLastQuery(queryNum, moduleNum, userNum);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }


       /// <summary>
       /// 根据用户编号、模块编号来查询查询主表表格
       /// </summary>
       /// <returns></returns>
       public sysDataSet.queryMasterDataTable getqueryMasterAll(string userNum,string moduleNum)
       {
           try
           {
               return queryMasterAdapter.GetDataByQueryMasterByUserQuerlList(userNum, moduleNum);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }

        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int queryMasterInsert(queryMasterModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                queryMasterDAL queryMaster = new queryMasterDAL(tn, conn);
                queryMaster.queryMasterInsert(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int queryMasterUpdate(queryMasterModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                queryMasterDAL queryMaster = new queryMasterDAL(tn, conn);
                queryMaster.queryMasterUpdate(row);
                tn.Commit();
                return i;

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

       public int queryMasterDel(string queryNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                queryMasterDAL queryMaster = new queryMasterDAL(tn, conn);
                queryMaster.queryMasterDel(queryNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
